package com.example.textview;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.textview.util.ToastUtil;

public class DialogActivity extends AppCompatActivity {

    private Button mbtn_dialog1,mbtn_dialog2,mbtn_dialog3,mbtn_dialog4,mbtn_dialog5,mbtn_dialog6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog);

        mbtn_dialog1=findViewById(R.id.btn_dialog1);
        mbtn_dialog2=findViewById(R.id.btn_dialog2);
        mbtn_dialog3=findViewById(R.id.btn_dialog3);
        mbtn_dialog4=findViewById(R.id.btn_dialog4);
        mbtn_dialog5=findViewById(R.id.btn_dialog5);
        mbtn_dialog6=findViewById(R.id.btn_dialog6);
        Onclick onclick=new Onclick();
        mbtn_dialog1.setOnClickListener(onclick);
        mbtn_dialog2.setOnClickListener(onclick);
        mbtn_dialog3.setOnClickListener(onclick);
        mbtn_dialog4.setOnClickListener(onclick);
        mbtn_dialog5.setOnClickListener(onclick);
        mbtn_dialog6.setOnClickListener(onclick);



    }

    class  Onclick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            switch (view.getId())
            {

                case R.id.btn_dialog1:
                    Toast.makeText(DialogActivity.this,"btn_dialog1",Toast.LENGTH_SHORT).show();
                    AlertDialog.Builder builder =new AlertDialog.Builder(DialogActivity.this);
                    builder.setTitle("请回答");
                    builder.setIcon(R.drawable.camera_1);
                    builder.setMessage("你觉得课程如何?")
                            .setPositiveButton("好", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Toast.makeText(DialogActivity.this,"你很测试",Toast.LENGTH_SHORT).show();
                                }
                            }).setNegativeButton("一般", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(DialogActivity.this,"你很测试1",Toast.LENGTH_SHORT).show();
                        }
                    }).show();


                    break;
                case R.id.btn_dialog2:
                    Toast.makeText(DialogActivity.this,"btn_dialog2",Toast.LENGTH_SHORT).show();
                    final String[] array=new String[]{"男","女"};

                    AlertDialog.Builder builder1=new AlertDialog.Builder(DialogActivity.this);
                    builder1.setTitle("请选择性别").setItems(array, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(DialogActivity.this,array[i],Toast.LENGTH_SHORT).show();
                        }
                    }).show();

                    break;
                case R.id.btn_dialog3:
                    final String[] array2=new String[]{"男","女"};

                    AlertDialog.Builder builder2=new AlertDialog.Builder(DialogActivity.this);
                    builder2.setCancelable(false);//点击旁边不会消失

                    builder2.setTitle("请选择性别").setSingleChoiceItems(array2, 0, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(DialogActivity.this,array2[i],Toast.LENGTH_SHORT).show();
                            dialogInterface.dismiss();//点击后会消失
                        }
                    }).show();
                    break;
                case R.id.btn_dialog4:

                    final String[] array4=new String[]{"唱歌","跳舞","打球"};
                     boolean[] is_seleeted=new boolean[]{false,false,false};
                    AlertDialog.Builder builder4=new AlertDialog.Builder(DialogActivity.this);
                    builder4.setTitle("选择兴趣");

                    builder4.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            Toast.makeText(DialogActivity.this,"12345",Toast.LENGTH_SHORT).show();
                        }
                    });

                    builder4.setMultiChoiceItems(array4, is_seleeted, new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                            Toast.makeText(DialogActivity.this,array4[i]+" :"+b,Toast.LENGTH_SHORT).show();
                        }
                    }).show();




                    break;


                case R.id.btn_dialog5:
                    AlertDialog.Builder builder5=new AlertDialog.Builder(DialogActivity.this);
                    View view1= LayoutInflater.from(DialogActivity.this).inflate(R.layout.layout_dialog,null);

                    Button btn_login= view1.findViewById(R.id.dl_btn);//特别注意前面有个view

                    if(btn_login!=null)
                    {
                    btn_login.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                           //
                        }
                    });}
                    else {
                        Toast.makeText(DialogActivity.this,"122222",Toast.LENGTH_SHORT).show();

                    }
                    builder5.setTitle("请先登录！").setView(view1).show();

                    break;


                case R.id.btn_dialog6:




                    final int[] h = {8};
                    final int[] s = {0};
                    AlertDialog.Builder builder6=new AlertDialog.Builder(DialogActivity.this);

                    View view2= LayoutInflater.from(DialogActivity.this).inflate(R.layout.layout_timepicker,null);

                    TimePicker timePicker=view2.findViewById(R.id.time_picker);
                    timePicker.setIs24HourView(true);
                    timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
                        @Override
                        public void onTimeChanged(TimePicker timePicker, int i, int i1) {
                            h[0] =i;
                            s[0] =i1;
                        }
                    });

                    Button btn_ok=view2.findViewById(R.id.btn_ok);
                    btn_ok.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            ToastUtil.showMsg(getApplicationContext(),"hour:"+h[0]+"secend:"+ s[0]);

                        }
                    });

                    builder6.setNegativeButton("取消",new DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ToastUtil.showMsg(getApplicationContext()," 你已经取消");
                        }
                    });

                    builder6.setPositiveButton("确定",new DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ToastUtil.showMsg(getApplicationContext(),"hour:"+h[0]+"secend:"+ s[0]);
                        }
                    });
                    builder6.setTitle("请选择时间").setView(view2).show();

                    break;
                default:

            }
        }
    }


}